<?php

  //////////////////////////////////////////////////////////////////
  // OrbitFAQ                                                     //
  // ---------                                                    //
  //                                                              //
  // Orbit FAQ was solely written and developed by Orbit Services //
  // http://www.orbitservices.net                                 //
  //                                                              //
  // Access the Forum here:                                       //
  // http://forums.orbitservices.net/index.php?c=4                //
  //                                                              //
  // OrbitFAQ utilises the following opensource projects/classes; //
  //  + Fckeditor - http://www.fckeditor.net                      //
  //  + Smarty Template Engine - http://smarty.php.net            //
  //  + Swift Email Class - http://www.swiftmailer.org/           //
  //  + OWASP PHP Filter Project - http://www.owasp.org           //
  //  + MySQL Search Class by Stephen Bartholomew                 //
  //                                                              //
  //////////////////////////////////////////////////////////////////
  
  /*
  


Unique Hits:
SELECT phpsessid, COUNT(*) FROM orbitfaq_stats GROUP BY phpsessid;

Most Popular Pages:
SELECT full_url, COUNT(*) FROM orbitfaq_stats GROUP BY full_url ORDER BY COUNT(*) DESC;

Most Popular FAQ:
SELECT f_id, COUNT(*) FROM orbitfaq_stats WHERE f_id != '0' GROUP BY f_id ORDER BY COUNT(*) DESC;

Most Popular Browser:
SELECT user_agent, COUNT(*) FROM orbitfaq_stats GROUP BY user_agent ORDER BY COUNT(*) DESC;
  
  */
  
  $statLIMIT = '10';
  
  $smarty_template_file = "$AdminFullPath/skins/$AdminSkin/mod_$mod.tpl";
  
  $smarty->assign("OrbitFAQTitle","FAQ Statistics");

  // Total Page Hits
  $query_hits = "SELECT id FROM orbitfaq_stats;";
  $result_hits = $faqsql_query ($query_hits)OR DIE( "$sql_query_error $query_hits");
  $count_hits = $faqsql_count_rows($result_hits);
  
  $smarty->assign('TotalPageHites',$count_hits);
  
  // Total Unique Page Hits by phpsessid
  $query_uhits = "SELECT phpsessid, COUNT(*) FROM orbitfaq_stats GROUP BY phpsessid;";
  $result_uhits = $faqsql_query ($query_uhits)OR DIE( "$sql_query_error $query_uhits");
  $count_uhits = $faqsql_count_rows($result_uhits);
  
   $smarty->assign('TotalUniquePageHites',$count_uhits);
  
  // Top 20 Most Popular Pages
  $query_poppgs = "SELECT full_url, COUNT(*) FROM orbitfaq_stats GROUP BY full_url ORDER BY COUNT(*) DESC LIMIT $statLIMIT";
  $result_poppgs = $faqsql_query ($query_poppgs)OR DIE( "$sql_query_error $query_poppgs");

  while ($row_poppgs = $faqsql_fetch_array ($result_poppgs)){
        $poppgs_full_url = $row_poppgs[0];
        $poppgs_count = $row_poppgs[1];
        
        if($row_class == '1')
          {
            $row_class = '0';
          }
        else
          {
            $row_class = '1';
          }
        
         $smarty_poppgs_array[] = array(
            "poppgs_full_url" => $poppgs_full_url,
            "poppgs_count" => $poppgs_count,
            "row_class" => $row_class
          );
  }
  
  $smarty->assign('PopularPagesListing',$smarty_poppgs_array);
  
  // Top 20 Most Popular Browsers
  $query_popagent = "SELECT user_agent, COUNT(*) FROM orbitfaq_stats GROUP BY user_agent ORDER BY COUNT(*) DESC LIMIT $statLIMIT";
  $result_popagent = $faqsql_query ($query_popagent)OR DIE( "$sql_query_error $query_popagent");

  while ($row_popagent = $faqsql_fetch_array ($result_popagent)){
        $popagent_agent = $row_popagent[0];
        $popagent_count = $row_popagent[1];
        
        if($row_class == '1')
          {
            $row_class = '0';
          }
        else
          {
            $row_class = '1';
          }
        
         $smarty_popagent_array[] = array(
            "popagent_agent" => $popagent_agent,
            "popagent_count" => $popagent_count,
            "row_class" => $row_class
          );
  }
  
  $smarty->assign('PopularBrowsersListing',$smarty_popagent_array);
  
  // Top 20 Most FAQS
  $query_popfaq = "SELECT orbitfaq_stats.f_id, orbitfaq.title, COUNT(*) FROM orbitfaq_stats, orbitfaq WHERE (orbitfaq_stats.f_id = orbitfaq.id) GROUP BY orbitfaq_stats.f_id ORDER BY COUNT(*) DESC LIMIT $statLIMIT";
  $result_popfaq = $faqsql_query ($query_popfaq)OR DIE( "$sql_query_error $query_popfaq");

  while ($row_popfaq = $faqsql_fetch_array ($result_popfaq)){
        $popfaq_id = $row_popfaq[0];
        $popfaq_title = $row_popfaq[1];
        $popfaq_count = $row_popfaq[2];
        
        if($row_class == '1')
          {
            $row_class = '0';
          }
        else
          {
            $row_class = '1';
          }
        
         $smarty_popfaq_array[] = array(
            "popfaq_title" => $popfaq_title,
            "popfaq_count" => $popfaq_count,
            "row_class" => $row_class
          );
  }
  
  $smarty->assign('PopularFAQListing',$smarty_popfaq_array);
  
  // Top 20 Most Categories
  $query_popcat = "SELECT orbitfaq_stats.c_id, orbitfaq_categories.title, orbitfaq_stats.f_id, orbitfaq.title, COUNT(*) FROM orbitfaq, orbitfaq_stats, orbitfaq_categories WHERE (orbitfaq_stats.c_id = orbitfaq_categories.id) AND (orbitfaq_stats.f_id = orbitfaq.id) GROUP BY orbitfaq_stats.f_id ORDER BY COUNT(*) DESC LIMIT $statLIMIT";
  $result_popcat = $faqsql_query ($query_popcat)OR DIE( "$sql_query_error $query_popcat");

  while ($row_popcat = $faqsql_fetch_array ($result_popcat)){
        $popcat_id = $row_popcat[0];
        $popcat_title = $row_popcat[1];
        $popcat_fid = $row_popcat[2];
        $popcat_ftitle = $row_popcat[3];
        $popcat_count = $row_popcat[4];
        
        if($row_class == '1')
          {
            $row_class = '0';
          }
        else
          {
            $row_class = '1';
          }
        
         $smarty_popcat_array[] = array(
            "popcat_ftitle" => $popcat_ftitle,
            "popcat_title" => $popcat_title,
            "popcat_count" => $popcat_count,
            "row_class" => $row_class
          );
  }
  
  $smarty->assign('PopularCATListing',$smarty_popcat_array);
  
?>